<?php
require_once '../incls/php/dbutils.class.php';
exec_inst();
function exec_inst() {
  $myPdo = DbUtils::createPdoInst();
  
  try {
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_plugin` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `folder` varchar(256) DEFAULT '' UNIQUE
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_ui` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `folder` varchar(256) DEFAULT '' UNIQUE
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_plugin_instance` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `page_id` int DEFAULT 0,
             `plugin_id` int DEFAULT 0,
             `name` varchar(256) DEFAULT '',
             `width` varchar(16) DEFAULT '',
             `height` varchar(16) DEFAULT '',
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_sys` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `script` varchar(256) DEFAULT '' UNIQUE,
             `ui_id` int DEFAULT 0,
             `is_login_required` tinyint(1) DEFAULT 0,
             `title` text DEFAULT NULL,
             `description` text DEFAULT NULL,
             `keywords` text DEFAULT NULL
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_page` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `sys_id` int DEFAULT 0,
             `parent_id` int DEFAULT 0,
             `order` double DEFAULT 0,
             `title` text DEFAULT NULL,
             `description` text DEFAULT NULL,
             `keywords` text DEFAULT NULL,
             `is_default` tinyint(1) DEFAULT 0,
             `is_visible` tinyint(1) DEFAULT 0,
             `html` longtext DEFAULT NULL,
             `css` longtext DEFAULT NULL,
             `js` longtext DEFAULT NULL,
             `path` varchar(256) DEFAULT ''
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $sql = "CREATE TABLE IF NOT EXISTS `pz2_profile` (
             `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
             `email` varchar(256) DEFAULT '' UNIQUE,
             `password` varchar(256) DEFAULT '',
             `mail_host` varchar(256) DEFAULT '',
             `mail_SMTPAuth` tinyint(1) DEFAULT 0,
             `mail_account` varchar(256) DEFAULT '',
             `mail_password` varchar(256) DEFAULT '',
             `mail_from_mail` varchar(256) DEFAULT '',
             `mail_from_name` varchar(256) DEFAULT ''
            ) ENGINE=MYISAM;";
    $myPdo->exec($sql);
    
    $tmp = DbUtils::get($myPdo, 'pz2_profile', NULL, NULL, NULL, NULL, NULL, NULL)->d;
    if (count($tmp) == 0) {
      $obj = new stdClass();
      $obj->email = 'luckyweida@gmail.com';
      $obj->password = md5('123456');
      DbUtils::add($myPdo, 'pz2_profile', $obj);
    }
  } catch (PDOException $e) {
    echo $e->getMessage();
  }
  return true;
}
?>